home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / New WASTE Handlers / New Pict Handler / WEObjectPicture.c next >
Text File  |  1995-06-07  |  3KB  |  88 lines

  1. // ————• WASTE Picture Object——————————————————————————————————————————————————————————
  2. // ———• by Michael F. Kamprath, kamprath@earthlink.net
  3.  
  4. // ————• Includes——————————————————————————————————————————————————————————————————————
  5.  
  6. #include "WEObjectPicture.h"
  7.  
  8. // ————• Macros————————————————————————————————————————————————————————————————————————
  9.  
  10. #define ThrowIfOSErr_(x) if(x != noErr) goto Exit
  11.  
  12. // ————• Static Prototypes—————————————————————————————————————————————————————————————
  13.  
  14. static pascal OSErr    HandleNewPicture(Point *defaultObjectSize, WEObjectReference objectRef);
  15. static pascal OSErr    HandleDisposePicture(WEObjectReference objectRef );
  16. static pascal OSErr    HandleDrawPicture(Rect *destRect, WEObjectReference objectRef );
  17.  
  18. static UniversalProcPtr    sNewPictRD;
  19. static UniversalProcPtr    sDisposePictRD;
  20. static UniversalProcPtr    sDrawPictRD;
  21.  
  22. // ————• Installer——————————————————————————————————————————————————————————————————————
  23.  
  24. OSErr WEObjPictureInstall(WEHandle inWaste)
  25. {
  26.     OSErr theErr = noErr;
  27.     
  28.     if(sNewPictRD == NULL)
  29.     {
  30.         sNewPictRD = NewWENewObjectProc(HandleNewPicture);
  31.         sDisposePictRD = NewWEDisposeObjectProc(HandleDisposePicture);
  32.         sDrawPictRD = NewWEDrawObjectProc(HandleDrawPicture);
  33.     }
  34.     
  35.     theErr = WEInstallObjectHandler('PICT', weNewHandler, sNewPictRD, inWaste);
  36.     ThrowIfOSErr_(theErr);
  37.     
  38.     theErr = WEInstallObjectHandler('PICT', weDisposeHandler, sDisposePictRD, inWaste);
  39.     ThrowIfOSErr_(theErr);
  40.     
  41.     theErr = WEInstallObjectHandler('PICT', weDrawHandler, sDrawPictRD, inWaste);
  42.     ThrowIfOSErr_(theErr);
  43.  
  44. Exit:    
  45.     return theErr;
  46. }
  47.  
  48. // ————• New handler—————————————————————————————————————————————————————————————————————
  49. pascal OSErr    HandleNewPicture(Point *defaultObjectSize,WEObjectReference objectRef)
  50. {
  51.     PicHandle    thePic;
  52.     Rect        theFrame;
  53.  
  54.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  55.     
  56.     theFrame = (*thePic)->picFrame;
  57.     
  58.     OffsetRect(&theFrame, -theFrame.left, -theFrame.top);
  59.     
  60.     *defaultObjectSize = botRight(theFrame);
  61.         
  62.     return(noErr);
  63. }
  64.  
  65. // ————• Dispose handler—————————————————————————————————————————————————————————————————
  66. pascal OSErr    HandleDisposePicture(WEObjectReference objectRef )
  67. {
  68.     PicHandle    thePic;
  69.  
  70.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  71.     
  72.     if (thePic)
  73.         KillPicture(thePic);
  74.  
  75.     return(MemError());
  76. }
  77.  
  78. // ————• Draw handler————————————————————————————————————————————————————————————————————
  79. pascal OSErr    HandleDrawPicture (Rect *destRect, WEObjectReference objectRef )
  80. {
  81.     PicHandle    thePic;
  82.     
  83.     thePic = (PicHandle)WEGetObjectDataHandle(objectRef);
  84.  
  85.     DrawPicture(thePic, destRect);
  86.             
  87.     return( noErr );
  88. }